package com.huawei.appmarket.framework.widget;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.graphics.Canvas;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.Path.Direction;
import android.graphics.PorterDuffXfermode;
import android.graphics.RectF;
import android.graphics.drawable.BitmapDrawable;
import android.util.AttributeSet;
import android.widget.ImageView;

public class ClipRoundImageView extends ImageView {
    private PorterDuffXfermode ʻ;
    private Bitmap ʽ;
    private int ˊ;
    float ˋ;
    float ˎ;
    private int ˏ;
    private int ॱ;
    private Paint ॱॱ;

    public ClipRoundImageView(android.content.Context r6, android.util.AttributeSet r7, int r8) {
        /* JADX: method processing error */
/*
Error: java.util.NoSuchElementException
	at java.util.HashMap$HashIterator.nextNode(HashMap.java:1444)
	at java.util.HashMap$KeyIterator.next(HashMap.java:1466)
	at jadx.core.dex.visitors.blocksmaker.BlockFinallyExtract.applyRemove(BlockFinallyExtract.java:535)
	at jadx.core.dex.visitors.blocksmaker.BlockFinallyExtract.extractFinally(BlockFinallyExtract.java:175)
	at jadx.core.dex.visitors.blocksmaker.BlockFinallyExtract.processExceptionHandler(BlockFinallyExtract.java:79)
	at jadx.core.dex.visitors.blocksmaker.BlockFinallyExtract.visit(BlockFinallyExtract.java:51)
	at jadx.core.dex.visitors.DepthTraversal.visit(DepthTraversal.java:31)
	at jadx.core.dex.visitors.DepthTraversal.visit(DepthTraversal.java:17)
	at jadx.core.ProcessClass.process(ProcessClass.java:37)
	at jadx.api.JadxDecompiler.processClass(JadxDecompiler.java:306)
	at jadx.api.JavaClass.decompile(JavaClass.java:62)
*/
        /*
        r5 = this;
        r0 = 0;
        r5.<init>(r6, r7, r8);
        r1 = new android.graphics.Paint;
        r1.<init>();
        r5.ॱॱ = r1;
        r1 = new android.graphics.PorterDuffXfermode;
        r2 = android.graphics.PorterDuff.Mode.SRC_IN;
        r1.<init>(r2);
        r5.ʻ = r1;
        if (r7 == 0) goto L_0x0032;
    L_0x0016:
        r1 = o.ewm$o.ﹺ;
        r1 = r6.obtainStyledAttributes(r7, r1, r8, r0);
        r2 = o.ewm$o.ﾟॱ;	 Catch:{ RuntimeException -> 0x0033, all -> 0x0056 }
        r2 = r1.hasValue(r2);	 Catch:{ RuntimeException -> 0x0033, all -> 0x0056 }
        if (r2 == 0) goto L_0x002b;	 Catch:{ RuntimeException -> 0x0033, all -> 0x0056 }
    L_0x0024:
        r0 = o.ewm$o.ﾟॱ;	 Catch:{ RuntimeException -> 0x0033, all -> 0x0056 }
        r2 = 0;	 Catch:{ RuntimeException -> 0x0033, all -> 0x0056 }
        r0 = r1.getDimensionPixelSize(r0, r2);	 Catch:{ RuntimeException -> 0x0033, all -> 0x0056 }
    L_0x002b:
        r5.ˏ = r0;	 Catch:{ RuntimeException -> 0x0033, all -> 0x0056 }
        if (r1 == 0) goto L_0x0032;
    L_0x002f:
        r1.recycle();
    L_0x0032:
        return;
    L_0x0033:
        r0 = move-exception;
        r2 = "ClipRoundImageView";	 Catch:{ RuntimeException -> 0x0033, all -> 0x0056 }
        r3 = new java.lang.StringBuilder;	 Catch:{ RuntimeException -> 0x0033, all -> 0x0056 }
        r3.<init>();	 Catch:{ RuntimeException -> 0x0033, all -> 0x0056 }
        r4 = "CropRightRoundImageView init(AttributeSet attrs) ";	 Catch:{ RuntimeException -> 0x0033, all -> 0x0056 }
        r3 = r3.append(r4);	 Catch:{ RuntimeException -> 0x0033, all -> 0x0056 }
        r0 = r0.getMessage();	 Catch:{ RuntimeException -> 0x0033, all -> 0x0056 }
        r0 = r3.append(r0);	 Catch:{ RuntimeException -> 0x0033, all -> 0x0056 }
        r0 = r0.toString();	 Catch:{ RuntimeException -> 0x0033, all -> 0x0056 }
        o.dna.ˊ(r2, r0);	 Catch:{ RuntimeException -> 0x0033, all -> 0x0056 }
        if (r1 == 0) goto L_0x0032;
    L_0x0052:
        r1.recycle();
        goto L_0x0032;
    L_0x0056:
        r0 = move-exception;
        if (r1 == 0) goto L_0x005c;
    L_0x0059:
        r1.recycle();
    L_0x005c:
        throw r0;
        */
        throw new UnsupportedOperationException("Method not decompiled: com.huawei.appmarket.framework.widget.ClipRoundImageView.<init>(android.content.Context, android.util.AttributeSet, int):void");
    }

    public ClipRoundImageView(Context context) {
        this(context, null);
    }

    public ClipRoundImageView(Context context, AttributeSet attributeSet) {
        this(context, attributeSet, 0);
    }

    protected void onDraw(Canvas canvas) {
        this.ˋ = ˏ();
        this.ˎ = ˎ();
        ˎ(canvas, getMeasuredWidth(), getMeasuredHeight());
    }

    protected float ˏ() {
        if (getDrawable() != null && (getDrawable() instanceof BitmapDrawable)) {
            Bitmap bitmap = ((BitmapDrawable) getDrawable()).getBitmap();
            this.ॱ = bitmap.getWidth();
            this.ˊ = bitmap.getHeight();
        }
        if (((float) getMeasuredHeight()) / ((float) this.ˊ) <= ((float) getMeasuredWidth()) / ((float) this.ॱ)) {
            return 0.0f;
        }
        float measuredHeight = (((float) getMeasuredHeight()) / ((float) this.ˊ)) * ((float) this.ॱ);
        if (measuredHeight > ((float) getMeasuredWidth())) {
            measuredHeight = (measuredHeight - ((float) getMeasuredWidth())) / 2.0f;
        } else {
            measuredHeight = 0.0f;
        }
        this.ˋ = measuredHeight;
        return this.ˋ;
    }

    private void ˎ(Canvas canvas, int i, int i2) {
        int saveLayer = canvas.saveLayer(0.0f, 0.0f, (float) i, (float) i2, null, 31);
        this.ʽ = ˎ(i, i2);
        canvas.drawBitmap(this.ʽ, 0.0f, 0.0f, this.ॱॱ);
        this.ॱॱ.setXfermode(this.ʻ);
        Matrix matrix = new Matrix();
        matrix.setScale(this.ˎ, this.ˎ);
        if (getDrawable() instanceof BitmapDrawable) {
            canvas.drawBitmap(((BitmapDrawable) getDrawable()).getBitmap(), matrix, this.ॱॱ);
        }
        this.ॱॱ.setXfermode(null);
        canvas.restoreToCount(saveLayer);
    }

    private Bitmap ˎ(int i, int i2) {
        Bitmap createBitmap = Bitmap.createBitmap(i, i2, Config.ARGB_8888);
        Canvas canvas = new Canvas(createBitmap);
        Path path = new Path();
        path.addRoundRect(new RectF(0.0f, 0.0f, (float) i, (float) i2), new float[]{(float) this.ˏ, (float) this.ˏ, (float) this.ˏ, (float) this.ˏ, (float) this.ˏ, (float) this.ˏ, (float) this.ˏ, (float) this.ˏ}, Direction.CW);
        Paint paint = new Paint(1);
        paint.setColor(-16711936);
        canvas.drawPath(path, paint);
        return createBitmap;
    }

    private float ˎ() {
        if (this.ˊ == 0 && this.ॱ == 0) {
            return 1.0f;
        }
        return Math.max(((float) getMeasuredHeight()) / ((float) this.ˊ), ((float) getMeasuredWidth()) / ((float) this.ॱ));
    }
}
